home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 May: Tool Chest / Developer CD Series May 1996 (Tool Chest) (Apple Computer) (1996).iso / Sample Code / SCSI Samples 1.0 / SCSI Async Sample 06⁄15 ƒ / Src / SCSIAsyncSample.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-06-16  |  9.9 KB  |  415 lines  |  [TEXT/KAHL]

  1. /*                                SCSIAsyncSample.h                                */
  2. /*
  3.  * SCSIAsyncSample.h
  4.  * Copyright © 1992-93 Apple Computer Inc. All Rights Reserved.
  5.  */
  6. #define kApplicationCreator    '????'
  7.  
  8. #define MBAR_MenuBar        1000
  9. #define MENU_Apple            1
  10. #define MENU_File            128
  11. #define MENU_Edit            129
  12. #define STRS_SenseBase        1000
  13. #define DLOG_About            128
  14. #define DLOG_Query            129
  15. #define ALRT_NoNewSCSI        9000
  16. #define ALRT_FatalError        9001
  17. #define ALRT_NoMemory        9002
  18. #define ALRT_NonFatalError    9003
  19. #define ACUR_Animator        128
  20.  
  21. #define kMinWindowWidth        200
  22. #define kMinWindowHeight    300
  23. #define kLogLines            512
  24. #define kRequestMemory        100
  25.  
  26. #ifndef REZ
  27. #ifndef THINK_C                /* MPW includes            */
  28. #include <Errors.h>
  29. #include <Script.h>
  30. #include <Types.h>
  31. #include <Resources.h>
  32. #include <QuickDraw.h>
  33. #include <Fonts.h>
  34. #include <Events.h>
  35. #include <Windows.h>
  36. #include <ToolUtils.h>
  37. #include <Memory.h>
  38. #include <Menus.h>
  39. #include <Lists.h>
  40. #include <Printing.h>
  41. #include <Dialogs.h>
  42. #include <Packages.h>
  43. #include <Controls.h>
  44. #endif
  45.  
  46. /*
  47.  * These definitions are only for the code files.
  48.  */
  49. #ifndef TRUE
  50. #define TRUE    1
  51. #define FALSE    0
  52. #endif
  53. #ifndef EXTERN
  54. #define EXTERN    extern
  55. #endif
  56.  
  57. #include "SCSIDefinitions.h"
  58. #include "LogManager.h"
  59. #include "MicrosecondTrap.h"
  60.  
  61. /*
  62.  * Include the O.S. files in a specific order to make sure that we have
  63.  * a definition for the _SCSIAtomic trap.
  64.  */
  65. #include <Traps.h>
  66. #ifndef _SCSIAtomic
  67. #define _SCSIAtomic    0xA089
  68. #endif
  69. /*
  70.  * Note that this uses a later version of <Scsi.h> than is available in
  71.  * the published headers.
  72.  */
  73. #include "Scsi.h"
  74.  
  75. #define kScrollBarWidth        16
  76. #define kScrollBarOffset    (kScrollBarWidth - 1)
  77.  
  78. /*
  79.  * Items in the Apple Menu
  80.  */
  81. enum {
  82.     kAppleAbout = 1
  83. };
  84.  
  85. /*
  86.  * Items in the File Menu
  87.  */
  88. enum {
  89.     kFileCreateLogFile = 1,
  90.     kFileCloseLogFile,
  91.     kFileUnused1,
  92.     kFilePageSetup,
  93.     kFilePrint,
  94.     kFileUnused2,
  95.     kFileDebug,
  96.     kFileUnused3,
  97.     kFileQuit
  98. };
  99.  
  100. enum EditMenu {
  101.     kEditUndo                = 1,
  102.     kEditUnused,
  103.     kEditCut,
  104.     kEditCopy,
  105.     kEditPaste,
  106.     kEditClear
  107. };
  108.  
  109. /*
  110.  * Items in the Query Dialog
  111.  */
  112. enum {
  113.     kQueryTest = 1,
  114.     kQueryFinished,
  115.     kQueryHostBus,
  116.     kQueryTargetID,
  117.     kQueryTotalRequests,
  118.     kQueryBlocksPerTransfer,
  119.     kQueryTimeout,
  120.     kQueryEnableAsync,
  121.     kQueryEnableDisconnect,
  122.     kQueryRandomSeek,
  123.     kQueryThreadNumber,
  124.     kQueryVendorID,
  125.     kQueryProduct,
  126.     kQueryLogicalBlockLength,
  127.     kQueryBlocksOnDevice
  128. };
  129.  
  130. typedef struct VMHoldRecord {
  131.     void                *ptr;
  132.     unsigned long        size;
  133. } VMHoldRecord, *VMHoldPtr;
  134. enum {
  135.     kVMFunction = 0,
  136.     kVMStack,
  137.     kVMParam,
  138.     kVMBuffer,
  139.     kVMSense,
  140.     kVMSize            /* Must be last */
  141. };
  142.  
  143. typedef struct RequestMemory {
  144.     unsigned long        blockNumber;
  145.     UnsignedWide        startTime;
  146.     UnsignedWide        endTime;
  147. } RequestMemory, *RequestMemoryPtr;
  148. /*
  149.  * This is the information we need for each execution thread. They are
  150.  * created by the query dialog loop. These records are stored in
  151.  * permanent physical memory (HoldMemory)
  152.  */
  153. struct InfoRecord {
  154.     struct ScsiCmdBlock    *link;                    /* Queue link pointer            */
  155.     short                qType;                    /* Unused for OSQueue            */
  156.     SCSIExecIOPB        *pb;                    /* For SCSI Mgr Request            */
  157.     unsigned long        pbSize;                    /* Sizeof param block            */
  158.     Ptr                    bufferPtr;                /* -> transfer buffer            */
  159.     unsigned long        bufferLength;            /* == allocated length            */
  160.     unsigned short        threadIndex;            /* Which thread is it            */
  161.     Boolean                deviceActive;            /* TRUE when busy                */
  162.     Boolean                testCompleted;            /* TRUE when finished            */
  163.     unsigned long        completionTimeout;        /* I/O Timeout                    */
  164.     unsigned long        transferQuantum;        /* Transfer quantum                */
  165.     unsigned long        randomSeed;                /* Random number for seek test    */
  166. /* Data from the dialog */
  167.     DeviceIdent            deviceIdent;            /* Bus/Target/LUN                */
  168.     unsigned long        transferSizeBlocks;        /* Blocks to transfer            */
  169.     unsigned long        totalTransfers;            /* Transfers to perform            */
  170.     unsigned long        transfersAttempted;        /* Calls to SCSIAction            */
  171.     Boolean                enableAsync;            /* Asynch checked?                */
  172.     Boolean                enableDisconnect;        /* Disconnect checked?            */
  173.     Boolean                enableRandomSeek;        /* Random seek test                */
  174. /* Data resulting from Read Capacity */
  175.     unsigned long        totalLogicalBlocks;        /* Blocks on device                */
  176.     unsigned long        logicalBlockLength;        /* Logical block size            */
  177. /* Data resulting from Device Inquiry */
  178.     unsigned char        vendor[9];                /* Vendor name (pascal)            */
  179.     unsigned char        product[17];            /* Product ID (pascal)            */
  180. /* Data changed by/for each transfer request */
  181.     OSErr                finalStatus;            /* First detected error            */
  182.     SCSI_Command        command;                /* == Current command            */
  183.     unsigned long        blockNumber;            /* Read from this block            */
  184.     unsigned long        blockCount;                /* Blocks to transfer            */
  185.     unsigned long        byteCount;                /* Bytes to transfer            */
  186.     unsigned long        nextBlockNumber;        /* Block to start next time        */
  187.     unsigned long        transfersCompleted;        /* I/O Completion count            */
  188.     unsigned long        asynchRequests;            /* Truely asychronous            */
  189.     unsigned char        statusByte;                /* Status Phase byte            */
  190.     SCSI_Sense_Data        senseData;                /* Gets Sense data                */
  191.     unsigned long        actualTransferCount;    /* TRUE transfer length            */
  192. /* VM state (set by DoSCSIExecIO, cleared by command completion) */
  193.     VMHoldRecord        vmHoldInfo[kVMSize];
  194. /* This is used for the setup dialog */
  195.     Boolean                validDevice;
  196. /* Statistics */
  197.     UnsignedWide        testStartTime;            /* Total testing start time        */
  198.     UnsignedWide        testEndTime;            /* Total testing end time        */
  199.     double                sampleSum;                /* For mean time (sum in uSec)    */
  200.     double                sampleSumSquare;        /* And standard deviation        */
  201.     RequestMemoryPtr    requestMemoryPtr;        /* Current request slot            */
  202.     RequestMemory        requestMemory[kRequestMemory];
  203. };
  204. typedef struct InfoRecord InfoRecord, *InfoPtr;
  205.  
  206. /*
  207.  * Processing functions
  208.  */
  209. void                            GetDevicesToTest(void);
  210. void                            DisplayTestParameters(void);
  211. void                            DisplayTestResults(void);
  212. void                            StartTesting(void);
  213. void                            ContinueTesting(void);
  214. pascal Boolean                    NumericFilter(
  215.         DialogPtr                    dp,
  216.         EventRecord                    *eventPtr,
  217.         short                        *itemHit
  218.     );
  219.  
  220. /*
  221.  * SCSI Executor
  222.  */
  223. OSErr                            DoSCSISynchronousIO(
  224.          InfoPtr                        infoPtr,
  225.         SCSI_CommandPtr                commandPtr,
  226.         unsigned long                scsiFlags,
  227.         Ptr                            bufferPtr,
  228.         unsigned long                transferLength
  229.     );
  230. short                            GetSCSICDBLength(
  231.         const SCSI_CommandPtr        scsiCommandPtr
  232.     );
  233.  
  234. /*
  235.  * Utility functions
  236.  */
  237. OSErr                            CheckForDevicePresent(
  238.         unsigned short                busID,
  239.         unsigned short                target,
  240.         unsigned short                LUN
  241.     );
  242. Boolean                            AsyncSCSIPresent(void);
  243. OSErr                            GetHostBusCount(
  244.         short                        *busCount
  245.     );
  246. void                            DoTestUnitReady(
  247.         unsigned short                busID,
  248.         unsigned short                target,
  249.         unsigned short                LUN
  250.     );
  251. void                            ExecuteSCSICommand(
  252.         register InfoPtr            infoPtr
  253.     );
  254. void                            IOCompletion(
  255.         SCSIExecIOPB                *ioPBPtr
  256.     );
  257.  
  258. /*
  259.  * Display and error logging
  260.  */
  261. void                            DisplayDeviceInfo(
  262.         register InfoPtr            infoPtr
  263.     );
  264. void                            AppendSCSIBusID(
  265.         StringPtr                    result,
  266.         DeviceIdent                    deviceIdent
  267.     );
  268. void                            ShowSCSIBusID(
  269.         register InfoPtr            infoPtr
  270.     );
  271. void                            ShowRequestSense(
  272.         register InfoPtr            infoPtr
  273.     );
  274. void                            ShowStatusError(
  275.         OSErr                        errorStatus,
  276.         unsigned short                cmdByte
  277.     );
  278. void                            DisplaySCSIErrorMessage(
  279.         OSErr                        errorStatus,
  280.         ConstStr255Param            errorText
  281.     );
  282. void                            NonFatalError(
  283.         OSErr                        errorStatus,
  284.         ConstStr255Param            errorMsg
  285.     );
  286. void                            FatalError(
  287.         OSErr                        errorStatus,
  288.         ConstStr255Param            errorMsg
  289.     );
  290. /*
  291.  * String formatting utilities.
  292.  */
  293. /*
  294.  * AppendChar writes a character into the string. Note that
  295.  * it wraps around if the string size exceeds 255 bytes.
  296.  */
  297. #define AppendChar(result, c) (result[++result[0]] = (c))
  298. void                            AppendUnsigned(
  299.         StringPtr                    result,
  300.         unsigned long                value
  301.     );
  302. void                            AppendSigned(
  303.         StringPtr                    result,
  304.         signed long                    value
  305.     );
  306. void                            AppendUnsignedLeadingZeros(
  307.         StringPtr                    result,
  308.         unsigned long                value,
  309.         short                        fieldWidth,
  310.         short                        terminatorChar
  311.     );
  312. void                        AppendHexLeadingZeros(
  313.         StringPtr                    result,
  314.         unsigned long                value,
  315.         short                        fieldWidth
  316.     );
  317. void                        AppendUnsignedInField(
  318.         StringPtr                    result,
  319.         unsigned long                value,
  320.         short                        fieldWidth
  321.     );
  322. void                        AppendBytes(
  323.         StringPtr                    result,
  324.         const Ptr                    source,
  325.         unsigned short                length
  326.     );
  327. void                        AppendPascalString(
  328.         StringPtr                    result,
  329.         const StringPtr                value
  330.     );
  331. void                        AppendCString(
  332.         StringPtr                    result,
  333.         const char                    *source,
  334.         unsigned short                maxLength        /* Ignored if zero    */
  335.     );
  336. void                        AppendOSType(
  337.         StringPtr                    result,
  338.         OSType                        value
  339.     );
  340. void                        AppendDouble(
  341.         StringPtr                    result,
  342.         double                        value,
  343.         unsigned short                decimalPlaces
  344.     );
  345.  
  346. /*
  347.  * Window Utilities
  348.  */
  349. void                            DoZoomWindow(
  350.         WindowPtr                    theWindow,
  351.         short                        whichPart
  352.     );
  353. Boolean                            DoGrowWindow(
  354.         WindowPtr                    theWindow,
  355.         Point                        eventWhere,
  356.         short                        minimumWidth,
  357.         short                        minimumHeight
  358.     );
  359. void                            MyDrawGrowIcon(
  360.         WindowPtr                    theWindow
  361.     );
  362.  
  363. /*
  364.  * Format a block of data into the log.
  365.  */
  366. void                            DisplayDataBlock(
  367.         Ptr                            dataPtr,
  368.         unsigned short                dataLength
  369.     );
  370.  
  371. void                            pstrcpy(
  372.         StringPtr                    destination,
  373.         ConstStr255Param            source
  374.     );
  375. void                            pstrcat(
  376.         StringPtr                    destination,
  377.         ConstStr255Param            source
  378.     );
  379. void                            ClearMemory(
  380.         Ptr                            dataPtr,
  381.         unsigned long                dataSize
  382.     );
  383. #define width(r)        ((r).right - (r).left)
  384. #define height(r)        ((r).bottom - (r).top)
  385. #define CLEAR(record)    ClearMemory((Ptr) &record, sizeof record);
  386.  
  387. /*
  388.  * Global variables.
  389.  */
  390. EXTERN WindowPtr                gMainWindow;
  391. EXTERN EventRecord                gCurrentEvent;
  392. #define EVENT                    (gCurrentEvent)
  393. EXTERN ListHandle                gLogListHandle;
  394. EXTERN THPrint                    gPrintHandle;
  395. EXTERN Boolean                    gQuitNow;
  396. EXTERN Boolean                    gStopNow;
  397. EXTERN Boolean                    gUpdateMenusNeeded;
  398. EXTERN Boolean                    gInForeground;
  399. EXTERN Boolean                    gVirtualMemoryEnabled;
  400. EXTERN MenuHandle                gAppleMenu;
  401. EXTERN MenuHandle                gFileMenu;
  402. EXTERN MenuHandle                gEditMenu;
  403. EXTERN short                    gMaxHostBus;
  404. EXTERN QHdr                        infoPtrQueue;    /* Known execution threads    */
  405.  
  406. /*
  407.  * VM Stuff
  408.  */
  409. extern void                        VMStartMarker(void);
  410. extern void                        VMEndMarker(void);
  411. #define kVMStackSize            4096
  412. EXTERN VMHoldRecord                gVMHoldRecord[kVMStack + 1];
  413.  
  414. #endif        /* REZ            */
  415.